"""
市场数据服务异常定义
==================

定义市场数据服务中使用的所有异常类型，支持精细化的错误处理和HTTP状态码映射
"""


class MarketDataException(Exception):
    """市场数据异常基类"""
    def __init__(self, message: str, details: dict = None):
        super().__init__(message)
        self.message = message
        self.details = details or {}


# ==================== 客户端错误 (4xx) ====================

class InvalidSymbolError(MarketDataException):
    """无效的交易标的代码 - 400 Bad Request"""
    pass


class InvalidDateRangeError(MarketDataException):
    """无效的日期范围 - 400 Bad Request"""
    pass


class InvalidFrequencyError(MarketDataException):
    """不支持的数据频率 - 400 Bad Request"""
    pass


class DataNotFoundError(MarketDataException):
    """数据未找到 - 404 Not Found"""
    pass


class DataSourceNotFoundError(MarketDataException):
    """数据源未找到 - 404 Not Found"""
    pass


# ==================== 服务端错误 (5xx) ====================

class DataSourceException(MarketDataException):
    """数据源异常 - 503 Service Unavailable"""
    pass


class AdapterException(DataSourceException):
    """适配器异常 - 503 Service Unavailable (兼容旧代码)"""
    pass


class CacheException(MarketDataException):
    """缓存异常 - 500 Internal Server Error"""
    pass


class ValidationException(MarketDataException):
    """数据验证异常 - 500 Internal Server Error"""
    pass


class RateLimitException(MarketDataException):
    """速率限制异常 - 429 Too Many Requests"""
    pass


class ConfigurationException(MarketDataException):
    """配置异常 - 500 Internal Server Error"""
    pass


class DatabaseWriteError(MarketDataException):
    """数据库写入错误 - 500 Internal Server Error"""
    pass


class AdapterNotAvailableError(MarketDataException):
    """适配器不可用 - 503 Service Unavailable"""
    pass
